package com.luoran.bartalks.core;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * @author lifetime
 *
 */
public class AppSessionInterceptor extends HandlerInterceptorAdapter {

	public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
		AppUser.clear();
		String token = req.getParameter("token");
		if(!StringUtils.isEmpty(token)) {
			UserContextInfo info = AppUser.get(token);
			AppUser.init(info);
		}
		resp.addHeader("Access-Control-Allow-Origin", "*");
		return true;
	}

}
